package com.aaa.system.dao;

import com.aaa.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @InterfaceName MenuDao
 * @Description
 * @Author 崔灿
 * @LastChangeDate 2023/2/27 9:25
 * @Version v1.0
 */

public interface MenuDao extends BaseMapper<Menu> {
    @Select("select distinct sm.* from sys_menu sm join sys_role_menu srm on sm.menu_id=srm.menu_id join sys_user_role sur on srm.role_id=sur.role_id where sur.user_id=#{userid}")
    List<Menu> selectPermissionByUserid(Integer userid);

    @Select("select user_id from sys_user where username=#{name}")
    Integer findUserid(String username);

    @Select("SELECT distinct m.* FROM sys_user_role ur INNER JOIN sys_role_menu rm ON ur.role_id=rm.role_id INNER JOIN sys_menu m ON rm.menu_id=m.menu_id WHERE user_id=#{userid}")
    List<Menu> findAllMenu(Integer userid);

    @Select("select m1.*,m2.menu_name parentName from sys_menu m1 left join sys_menu m2 on m1.parent_id=m2.menu_id")
    List<Menu> selectAll();
    @Select("SELECT count(*) FROM sys_menu m1 join sys_menu m2 on m1.menu_id=m2.parent_id where m1.menu_id=#{menuId}")
    Integer queryChildrenNumById(Integer menuId);
}
